/*
 *  Description: BOAT XU SOFT FHSS
 *  Version: V1.00
 *  Author: boat xu
 *  Email: xifengzui@outlook.com
 *  Date: 2020-07-14 16:54:10
 *  LastEditTime: 2020-07-22 13:44:51
 */ 
#include "string.h"
#include "bsf_types.h"
#include "bsf_itypes.h"
#include "bsf_payload.h"
#include "bsf_freqHopping.h"
#include "bsf_rand.h"
#include "bsf_misc_com.h"


void bsf_miscComFillSync(bsf_payload *inBuf)
{
    bsf_payloadInfoSet(b_pt_sync,0,inBuf);
}

void bsf_miscComFillSeedTable(bsf_payload *inBuf,b_u16_t seed, b_u8_t *table)
{
    bsf_MiscComSeedTable *st;
    st = (bsf_MiscComSeedTable *)inBuf->stru.payload;
    //todo create table struct
    st->seedL = (b_u8_t)(seed);
    st->seedH = (b_u8_t)(seed>>8);
    memcpy(st->table,table,BSF_RAND_FREQCUTNUM);
    bsf_payloadInfoSet(b_pt_seedTable,sizeof(bsf_MiscComSeedTable),inBuf);
    
}

void bsf_miscComFillUserData(bsf_payload *inBuf,b_u16_t index,b_u8_t *userData,b_u8_t userDataLen)
{
    bsf_MiscComUserData *ud;
    
    ud = (bsf_MiscComUserData *)inBuf->stru.payload;
    ud->indexL = (b_u8_t)(index);
    ud->indexH = (b_u8_t)(index>>8);
   
    // if userData == null ,it means the user operator the payload by other way, the msicCom fill will simple ignore that.
    if(userData != b_null)
    {
        memcpy(ud->userData,userData,userDataLen);
    }
    bsf_payloadInfoSet(b_pt_userData,userDataLen+2,inBuf);
}
